package frame

import "gitee.com/git_public/vfaith/builtin/vault"

//region 结构体定义

type BasicMapper struct {
	sqlMap       map[string]string
	sqlCondition map[string]func(*vault.QueryParam) error
}

func NewBasicMapper() *BasicMapper {
	return &BasicMapper{
		sqlMap:       make(map[string]string),
		sqlCondition: make(map[string]func(*vault.QueryParam) error),
	}
}

func (mapper *BasicMapper) SqlMap() map[string]string {
	return mapper.sqlMap
}

func (mapper *BasicMapper) SqlCondition() map[string]func(*vault.QueryParam) error {
	return mapper.sqlCondition
}

//endregion

// region 基础查询

func (mapper *BasicMapper) GetCount() string {
	return mapper.sqlMap["Count"]
}

func (mapper *BasicMapper) GetCollection() string {
	return mapper.sqlMap["Collection"]
}

func (mapper *BasicMapper) GetCondition() func(*vault.QueryParam) error {
	return mapper.sqlCondition["SearchCondition"]
}

func (mapper *BasicMapper) GetModel() string {
	return mapper.sqlMap["Model"]
}

func (mapper *BasicMapper) GetInsert() string {
	return mapper.sqlMap["Insert"]
}

func (mapper *BasicMapper) GetUpdate() string {
	return mapper.sqlMap["Update"]
}

func (mapper *BasicMapper) GetDelete() string {
	return mapper.sqlMap["Delete"]
}

// endregion

//region 初始化SQL CRUD

func (mapper *BasicMapper) SetCount(sql string) {
	mapper.sqlMap["Count"] = sql
}

func (mapper *BasicMapper) SetCollection(sql string) {
	mapper.sqlMap["Collection"] = sql
}

func (mapper *BasicMapper) SetCondition(f func(*vault.QueryParam) error) {
	mapper.sqlCondition["SearchCondition"] = f
}

func (mapper *BasicMapper) SetModel(sql string) {
	mapper.sqlMap["Model"] = sql
}

func (mapper *BasicMapper) SetInsert(sql string) {
	mapper.sqlMap["Insert"] = sql
}

func (mapper *BasicMapper) SetUpdate(sql string) {
	mapper.sqlMap["Update"] = sql
}

func (mapper *BasicMapper) SetDelete(sql string) {
	mapper.sqlMap["Delete"] = sql
}

//endregion
